package org.dreamwork.jasmine2.web.client;

import org.dreamwork.util.StringUtil;

import java.util.regex.Matcher;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-4-26
 * Time: 下午8:30
 */
public class AndroidMobileParser {
/*
Mozilla/5.0 (Linux; U; Android 2.2; zh-cn; GT-P1000 Build/FROYO) UC AppleWebKit/530+ (KHTML, like Gecko) Mobile Safari/530
group[1]=530+
group[2]=null
group[3]=null

Mozilla/5.0 (Linux; U; Android 2.2; zh-cn; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
group[1]=533.1
group[2]=Version/4.0
group[3]=4.0

Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; MOT-XT883/SLNCT-60.3.250; 540*960; CTC/2.0) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
group[1]=533.1
group[2]=Version/4.0
group[3]=4.0
 */
    public static UserAgent parse (Matcher m) {
        UserAgent agent = new UserAgent (m.group (0));
        agent.setDevice (DeviceType.Android);
        agent.setType (BrowserType.Chrome);

        OperationSystem os = OSParser.parseOS (m.group (0));
        agent.setOs (os);

        Version version = new Version (m.group (1));
        RenderKernel kernel = new RenderKernel (RenderkernelType.AppleWebKit, version);
        agent.setKernel (kernel);

        String s_version = m.group (3);
        if (StringUtil.isEmpty (s_version))
            agent.setVersion (Version.UNKNOWN);
        else
            agent.setVersion (new Version (m.group (3)));

        return agent;
    }
}
